/**
 * Created by ${PRODUCT_NAME}.
 * User: skylerparr
 * Date: 1/31/11
 * Time: 9:13 AM
 * To change this template use File | Settings | File Templates.
 */
package com.thoughtorigin.display.containers {
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.geom.Point;

public class Container extends Sprite {

    private var _rawChildContainer: Sprite;

    public function Container() {
        init();
    }

    protected function init(): void {
        _rawChildContainer = new Sprite();
        super.addChild(_rawChildContainer);
    }

    override public function addChild(child:DisplayObject):DisplayObject {
        var retVal: DisplayObject = _rawChildContainer.addChild(child);
        dispatchEvent(new ContainerEvent(ContainerEvent.RAW_CHILDREN_CHANGE, retVal, this));
        return retVal;
    }

    override public function addChildAt(child:DisplayObject, index:int):DisplayObject {
        var retVal: DisplayObject = _rawChildContainer.addChildAt(child, index);
        dispatchEvent(new ContainerEvent(ContainerEvent.RAW_CHILDREN_CHANGE, retVal, this));
        return retVal;
    }

    override public function getChildAt(index:int):DisplayObject {
        return _rawChildContainer.getChildAt(index);
    }

    override public function removeChild(child:DisplayObject):DisplayObject {
        var retVal: DisplayObject = _rawChildContainer.removeChild(child);
        dispatchEvent(new ContainerEvent(ContainerEvent.RAW_CHILDREN_CHANGE, retVal, this));
        return retVal;
    }

    override public function removeChildAt(index:int):DisplayObject {
        var retVal: DisplayObject = _rawChildContainer.removeChildAt(index);
        dispatchEvent(new ContainerEvent(ContainerEvent.RAW_CHILDREN_CHANGE, retVal, this));
        return retVal;
    }

    override public function get numChildren():int {
        return _rawChildContainer.numChildren;
    }

    override public function getChildIndex(child:DisplayObject):int {
        return _rawChildContainer.getChildIndex(child);
    }

    override public function setChildIndex(child:DisplayObject, index:int):void {
        _rawChildContainer.setChildIndex(child, index);
    }

    override public function getChildByName(name:String):DisplayObject {
        return _rawChildContainer.getChildByName(name);
    }

    override public function contains(child:DisplayObject):Boolean {
        return _rawChildContainer.contains(child);
    }

    override public function swapChildren(child1:DisplayObject, child2:DisplayObject):void {
        _rawChildContainer.swapChildren(child1, child2);
        dispatchEvent(new ContainerEvent(ContainerEvent.RAW_CHILDREN_CHANGE, null, this));
    }

    override public function swapChildrenAt(index1:int, index2:int):void {
        _rawChildContainer.swapChildrenAt(index1, index2);
        dispatchEvent(new ContainerEvent(ContainerEvent.RAW_CHILDREN_CHANGE, null, this));
    }

    internal function get rawChildContainer(): DisplayObjectContainer {
        return _rawChildContainer;
    }

    internal function addRawChild(value: DisplayObject): DisplayObject {
        return super.addChild(value);
    }

    internal function addRawChildAt(value: DisplayObject, index: int): DisplayObject {
        return super.addChildAt(value, index);
    }

    internal function removeRawChild(value: DisplayObject): DisplayObject {
        return super.removeChild(value);
    }

    internal function get rawNumChildren(): int {
        return super.numChildren;
    }

    public function removeRawChildAt(index:int):DisplayObject {
        return super.removeChildAt(index);
    }

    public function getRawChildAt(index:int):DisplayObject {
        return super.getChildAt(index);
    }

    public function rawContains(child:DisplayObject): Boolean {
        return super.contains(child);
    }

    internal function recalculateBounds(): void {
        dispatchEvent(new ContainerEvent(ContainerEvent.RECALCULATE_BOUNDS, null, this));
    }
}
}
